//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.user;

import com.ruoyi.live.app.service.AppService;
import com.ruoyi.live.base.domain.LiveExamTask;
import com.ruoyi.live.base.domain.LiveProduct;
import com.ruoyi.live.base.domain.LiveServer;
import com.ruoyi.live.base.domain.SystemParam;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.utils.Message;
import com.ruoyi.live.user.service.DeployService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/deploy"})
public class DeployController {
    private static final Logger log = LoggerFactory.getLogger(DeployController.class);
    @Autowired
    DeployService service;
    @Autowired
    AppService appService;

    public DeployController() {
    }

    @RequestMapping({"/video/upload"})
    public String upload() {
        return "/deploy/video_upload";
    }

    @RequestMapping({"uploadFile"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    @ResponseBody
    public Message uploadFile(Long id, MultipartFile file, HttpServletRequest request) {
        try {
            this.service.uploadFile(id, file, request);
            return new Message(true, "");
        } catch (Exception var5) {
            var5.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/index"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public ModelAndView index() {
        return this.service.index();
    }

    @ResponseBody
    @RequestMapping({"/listServers"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public List<LiveServer> listServers(HttpServletRequest request) {
        return this.service.listServers(request);
    }

    @ResponseBody
    @RequestMapping({"/getTaskData"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public List<LiveExamTask> getTaskData(Long examId) {
        return this.service.getTaskData(examId);
    }

    @ResponseBody
    @RequestMapping({"/getProductList"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public List<LiveProduct> getProductList() {
        return this.service.getProductList();
    }

    @ResponseBody
    @RequestMapping({"/getExamUserDetail"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Map<String, Integer> getExamUserDetail(Long examId) {
        return this.service.getExamUserDetail(examId);
    }

    @ResponseBody
    @RequestMapping({"/loadIndexUrl"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public List<SystemParam> loadIndexUrl() {
        return this.service.loadIndexUrl();
    }

    @ResponseBody
    @RequestMapping({"/editIndexUrl"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message editIndexUrl(Long id, String url) {
        try {
            this.service.editIndexUrl(id, url);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/addIndexUrl"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message addIndexUrl(String url) {
        try {
            this.service.addIndexUrl(url);
            return new Message(true, "");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/startCheck"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message startCheck(Long examId) {
        this.service.startCheck(examId);
        return new Message(true, "");
    }

    @ResponseBody
    @RequestMapping({"/startOneServer"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message startOneServer(Long id, HttpServletRequest request) {
        try {
            this.service.startOneServer(id, request);
            return new Message(true, "");
        } catch (IOException var4) {
            var4.printStackTrace();
        } catch (InterruptedException var5) {
            var5.printStackTrace();
        }

        return new Message(false, "");
    }

    @ResponseBody
    @RequestMapping({"/endExam"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message endExam(Long id, Long userId, Long examId) {
        try {
            if (ICommons.isNullOrEmpty(id)) {
                this.service.doInertJudgeEmpty(userId, examId);
            } else {
                this.appService.doEndExam(id);
            }

            return new Message(true, "交卷成功");
        } catch (Exception var5) {
            log.error("手动交卷失败：", var5);
            return new Message(false, "交卷失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/backup"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message backup(HttpServletRequest request, HttpServletResponse response) {
        return this.service.backup(request, response);
    }

    @ResponseBody
    @RequestMapping({"/checkMode"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message checkMode(Long userId) {
        try {
            this.service.checkMode(userId);
            return new Message(true, "");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "");
        }
    }
}
